<template>
  <div class="serviceredContent">
    <div class="serviceredTitle">
      <div class="customerTitle">海川医药客服冲红{{ systemTime }}日报</div>
      <div class="searchBtn">
        <el-date-picker
          v-model="dateRange"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="date"
        >
        </el-date-picker>
        <el-button type="success" @click="handleServicered">搜索</el-button>
      </div>
    </div>
    <div class="serviceredTable">
      <el-table
        :data="tableData"
        style="width: 100%"
        :cell-style="tableCellStyle"
        :header-cell-style="{
          background: '#1890ff',
          textAlign: 'center',
          color: '#fff',
          fontSize: '16px',
          fontWeight: 'bold',
        }"
      >
        <el-table-column
          prop="kcdsLh"
          label="库存短少(零货)"
          align="center"
          width="130px"
        >
          <template slot-scope="scope">
            <el-input v-model="scope.row.kcdsLh"></el-input>
          </template>
        </el-table-column>
        <el-table-column
          prop="kcdsZy"
          label="库存短少(中药)"
          align="center"
          width="130px"
        >
          <template slot-scope="scope">
            <el-input v-model="scope.row.kcdsZy"></el-input>
          </template>
        </el-table-column>
        <el-table-column
          prop="psyl"
          label="破损、易漏"
          align="center"
          width="130px"
        >
          <template slot-scope="scope">
            <el-input v-model="scope.row.psyl"></el-input>
          </template>
        </el-table-column>
        <el-table-column label="客户原因" align="center">
          <el-table-column
            prop="khyyKpyq"
            label="开票要求"
            align="center"
            width="130px"
          >
            <template slot-scope="scope">
              <el-input v-model="scope.row.khyyKpyq"></el-input>
            </template>
          </el-table-column>
          <el-table-column prop="khyyZbz" label="中包装" align="center">
            <template slot-scope="scope">
              <el-input v-model="scope.row.khyyZbz"></el-input>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column prop="hcyy" label="海川原因" align="center">
          <template slot-scope="scope">
            <el-input v-model="scope.row.hcyy"></el-input>
          </template>
        </el-table-column>
        <el-table-column prop="mbz" label="目标值" align="center">
          <template slot-scope="scope">
            <el-input v-model="scope.row.mbz"></el-input>
          </template>
        </el-table-column>
        <el-table-column prop="zchs" label="总冲红数" align="center">
          <template slot-scope="scope">
            <el-input v-model="scope.row.zchs"></el-input>
          </template>
        </el-table-column>
        <el-table-column prop="cktms" label="出库条目数" align="center">
          <template slot-scope="scope">
            <el-input v-model="scope.row.cktms"></el-input>
          </template>
        </el-table-column>
        <el-table-column prop="chl" label="冲红率" align="center" width="150px">
          <template slot-scope="scope">
            <div class="beakageRate">
              <el-input v-model="scope.row.chl"></el-input>
              <span>%</span>
            </div>
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
import { dailyaddjdc, dailylistjdc } from "@/api/system/daily";
export default {
  data() {
    return {
      // 陕西海通零货条目数
      ids: null,
      systemTime: "",
      dateRange: new Date().toISOString().split("T")[0],
      tableData: [
        {
          rbSj: new Date().toISOString().split("T")[0],
          xrkskut: "",
          rkjs: "",
          rkzbdcl: "",
          zkcjs: "",
          zskut: "",
          ckd: "",
          ckj: "",
          dbckdcl: "",
          zyscs: "",
          zysce: "",
        },
      ],
    };
  },
  mounted() {
    // 创建一个 Date 对象
    const currentDate = new Date();
    // 获取当前年份
    const year = currentDate.getFullYear();
    // 获取当前月份（注意：月份是从 0 开始计数的，所以需要加 1）
    const month = currentDate.getMonth() + 1;
    // 获取当前日期
    const day = currentDate.getDate();
    // 打印年月日
    this.systemTime = `${year}年${month}月${day}日`;
    this.getjdcList();
  },
  beforeDestroy() {},
  methods: {
    // 设置表格边框颜色
    tableCellStyle() {
      return "border-color: #181616";
    },
    // savejdcdaily() {
    //   console.log(111, this.tableData[0]);
    //   dailyaddjdc(this.tableData[0]).then((res) => {
    //     this.$modal.msgSuccess("新增成功");
    //     this.getjdcList();
    //   });
    // },
    handleServicered() {
      dailylistjdc().then((res) => {
        if (res.data) {
          let {
            xrkskut,
            rkjs,
            rkzbdcl,
            zkcjs,
            zskut,
            ckd,
            ckj,
            dbckdcl,
            zyscs,
            zysce,
          } = res.data;
          // this.$set(this.tableData, 0, res.data);
          // this.tableData[0] = {
          //   xrkskut,
          //   rkjs,
          //   rkzbdcl,
          //   zkcjs,
          //   zskut,
          //   ckd,
          //   ckj,
          //   dbckdcl,
          //   zysc,
          // };
          this.tableData[0].xrkskut = xrkskut;
          this.tableData[0].rkjs = rkjs;
          this.tableData[0].rkzbdcl = rkzbdcl;
          this.tableData[0].zkcjs = zkcjs;
          this.tableData[0].zskut = zskut;
          this.tableData[0].ckd = ckd;
          this.tableData[0].ckj = ckj;
          this.tableData[0].dbckdcl = dbckdcl;
          this.tableData[0].zyscs = zyscs;
          this.tableData[0].zysce = zysce;
        }
      });
    },
    getSummaries(param) {
      const { columns, data } = param;
      const sums = [];
      columns.forEach((column, index) => {
        // if (index === 6 || index === 7 || index === 8) {
        //   sums[index] = "";
        //   return;
        // } else if (index === 0) {
        //   sums[index] = "合计";
        //   return;
        // }
        if (index === 0) {
          sums[index] = "合计";
          return;
        }
        const values = data.map((item) => Number(item[column.property]));
        if (
          !values.every((value) => isNaN(value)) &&
          column.property != "rkzbdcl"
        ) {
          sums[index] = values.reduce((prev, curr) => {
            const value = Number(curr);
            if (!isNaN(value)) {
              return prev + curr;
            } else {
              return prev;
            }
          }, 0);
          sums[index] += "";
        }
      });

      return sums;
    },
  },
};
</script>

<style lang="scss" scoped>
.serviceredContent {
  width: 100%;
  height: 100%;
  ::v-deep .el-table__body-wrapper {
    border: 1px solid #181616;
  }
  .el-table--group::after,
  .el-table--border::after {
    background-color: #181616;
  }
  ::v-deep .el-table--enable-row-hover .el-table__body tr:hover > td {
    background-color: transparent;
  }
  ::v-deep .el-date-editor.el-input,
  .el-date-editor.el-input__inner {
    width: 100%;
  }
  // ::v-deep .el-input--prefix .el-input__inner {
  //   border: none;
  // }
  ::v-deep .el-table tr {
    height: 70px;
  }
  .beakageRate {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
  .serviceredTitle {
    width: 100%;
    text-align: center;
    .customerTitle {
      width: 100%;
      font-size: 30px;
      font-weight: 700;
      margin: 30px 0 20px 0;
    }
    ::v-deep .el-button--success {
      height: 36px;
      margin-left: 30px;
    }
  }
  .serviceredTable {
    width: 90%;
    margin-top: 20px;
    ::v-deep .el-table__footer-wrapper tbody td.el-table__cell {
      background: #75d561;
      color: #ff4800;
      font-weight: 700;
      font-size: 16px;
    }
    ::v-deep .el-input__inner {
      height: 65px;
      line-height: 65px;
      border: none;
      text-align: center;
      color: #000000;
      width: 100%;
    }
  }
}
</style>